package com.mentalhealthplatform.studentV3.controller;

import com.mentalhealthplatform.appModels.Tweet;
import com.mentalhealthplatform.studentV3.service.TweetServiceV3;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("api/v3/precaution")
public class TweetControllerV3 {

    @Autowired
    private TweetServiceV3 tweetServiceV3;

    @GetMapping("/tweets")
    public ResponseEntity<List<Tweet>> getAllTweets() {
        List<Tweet> tweets = tweetServiceV3.getAllTweets();
        return ResponseEntity.ok(tweets);
    }
    @GetMapping("/tweetDetail/{id}")
    public ResponseEntity<Tweet> getTweetById(@PathVariable Long id) {
        Tweet tweet = tweetServiceV3.getTweetById(id);
        if (tweet != null) {
            return ResponseEntity.ok(tweet);
        } else {
            return ResponseEntity.notFound().build();
        }
    }
    @PostMapping("/save")
    public ResponseEntity<Tweet> saveTweet(@RequestBody Tweet tweet) {
        Tweet savedTweet = tweetServiceV3.saveTweet(tweet);
        return ResponseEntity.ok(savedTweet);
    }

    @DeleteMapping("/delete/{id}")
    public ResponseEntity<Void> deleteTweetById(@PathVariable Long id) {
        tweetServiceV3.deleteTweetById(id);
        return ResponseEntity.noContent().build();
    }
    @GetMapping("/search")
    public ResponseEntity<List<Tweet>> searchTweets(@RequestParam String keyword) {
        List<Tweet> tweets = tweetServiceV3.searchTweets(keyword);
        return ResponseEntity.ok(tweets);
    }
}
